package com.centling.smartSealForPhone.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.centling.smartSealForPhone.service.UploadImageService;
import com.centling.smartSealForPhone.utils.LogUtil;

public class NetworkReceiver
        extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        ConnectivityManager connectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info;
        if (connectivityManager != null && (info = connectivityManager.getActiveNetworkInfo()) != null) {
            if (info.getType() == ConnectivityManager.TYPE_WIFI || info
                    .getType() == ConnectivityManager.TYPE_MOBILE) {
                LogUtil.d("现在的网络状态为：" + info.getType());
                if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                    context.startService(new Intent(context, UploadImageService.class));
                }
            }
        }
    }
}
